<%/*
 * Copyright (c) 2007
 *	Alberto Magni, Maggioni Marcello
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */%>
 
 <%-- 
    Document   : configuration
    Created on : 28-nov-2007, 18.26.39
    Author     : Marcello Maggioni
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.Map"%>
<%@page import="Database.*"%>
<%@ taglib uri="/WEB-INF/tlds/login" prefix="access" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>User Configuration Page</title>
    </head>
    <body>
        <h2>User Configuration Page</h2>
        <hr>
        <jsp:useBean id="loggedin" type="beans.LoginBean" scope="session"/>
        <access:LoginTag/>
        <jsp:include page="username.jsp"><jsp:param name="username" value="<%= loggedin.getUsername() %>"/></jsp:include>
        <% ConfigurationDB cdb = (ConfigurationDB) application.getAttribute("configurationdb");
           AddressesDB adb = (AddressesDB) application.getAttribute("addressesdb");
           String email = cdb.getEMailAddress(loggedin.getUsername());
           String server = cdb.getServer(loggedin.getUsername());
           String originalfilename = adb.getOriginalFilename(loggedin.getUsername());
           boolean srvauth = cdb.getServerAuthMode(loggedin.getUsername());
           if (email == null)
               email = "";
           if (server == null)
               server = cdb.getServer(null);
           if (server == null)
               server = ""; %>
        <h3>Set default addresses:</h3>
        <table>
        <form enctype="multipart/form-data" method=post action="UserConfigSrv" multipart>
            <tr><td><b>Currently Loaded File:</b><%if (originalfilename == null || originalfilename.isEmpty()) {
                out.print(" None");
            } else {
                out.print(" " + originalfilename);
            }%></td></tr>
            <tr><td>File (CSV, LDIF, XML):</td><td><input type=file name="fileupload"/></td>
            <tr><td><input type=submit value="Submit"/></td></tr>
        </form>
        </table>
        <h3>Set SMTP Server:</h3>
        <table>
        <form method=post action="UserConfigSrv">
            <tr><td>SMTP Server:</td><td><input type=text name="server" value="<%= server %>"/></td></tr>
            <tr><td><input type=submit value="Set"/></td></tr>
        </form>
        </table>
        <h3>Server Authentication</h3>
        <form method=post action="UserConfigSrv">
            <table>
                <tr><td><input type=checkbox name="srvauth" <%if (srvauth) { out.print("checked"); }%> value="enable"/></td> <td>Enable Server Authentication through SSL</td></tr>
                <tr><td><input type=submit name="srvauthbut" value="Set"/></td></tr>
        </table>
        </form>
        <h3>Set E-Mail Address:</h3>
        <table>
        <form method=post action="UserConfigSrv">
            <tr><td>E-Mail address:</td><td><input type=text name="mail" value="<%= email %>"/></td></tr>
            <tr><td><input type=submit value="Set"/></td></tr>
        </form>
        </table>
        <h3>Set New Password:</h3>
        <table>
        <form method=post action="UserConfigSrv">
            <tr><td>New Password:</td><td><input type=password name="password1"/></td></tr>
            <tr><td>New Password (Retype):</td><td><input type=password name="password2"/></td></tr>
            <tr><td><input type=submit value="Change"/></td></tr>
        </form>
        </table>
        <h3>Download Default Addresses</h3>
        <form method=post action="UserConfigSrv">
            <input type=submit name="download" value="Download"/>
        </form>
        <br>
        <form action="datainput.jsp"><input type=submit value="Back"/></form>
        <jsp:include page="logout.jsp"/>
    </body>
</html>